subroutine cgrid(i3,C1,nlw,C,glw,nc,gc)
INTEGER, INTENT(IN) :: i3, nlw, nc
REAL, INTENT(IN) :: C1
REAL, INTENT(IN) :: C(nlw,1), glw(nlw,1)
real, INTENT(OUT) :: gc(nc,1)
INTEGER :: i9
real :: maxc,minc,mpc,stepc
  
if (i3.eq.1) then
    maxc = C1
    minc = maxc/2
else
    minc = C(i3-1,1)
    if (i3<10) then
        maxc = C(i3-1,1) + (glw(i3,1) - glw(i3-1,1))
    else
  !the max below does not impose an mpc>0.05, only sets it as a minimum for the maximum grid value later on      
        mpc = max((C(i3-1,1)-C(i3-9,1))/(glw(i3-1,1) - glw(i3-9,1)),0.05) 
        maxc = C(i3-1,1) + mpc*(glw(i3,1) - glw(i3-1,1))      
    end if         
end if
stepc=(maxc-minc)/(nc-1)
DO i9=1,nc
   gc(i9,1)=minc+(i9-1.0)*stepc
END DO

end subroutine
